/**
 * 
 */
package org.jackysoft.controller;

import java.util.Collection;
import java.util.SortedMap;

import javax.annotation.Resource;

import org.jackysoft.controller.base.AbstractController;
import org.jackysoft.entity.FieldAccess;
import org.jackysoft.entity.HtmlFormTemplate;
import org.jackysoft.entity.WorkflowNode;
import org.jackysoft.service.FieldAccessService;
import org.jackysoft.service.FormService;
import org.jackysoft.service.HtmlTemplateService;
import org.jackysoft.service.WorkflowNodeService;
import org.jackysoft.util.WorkflowUtil;
import org.jackysoft.workflow.Workflow;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author qujiakang
 * 
 */

@Controller
@RequestMapping("/fieldaccess")
public class FieldAccessController extends AbstractController<FieldAccess> {

	/**
	 * 
	 */
	
	
	@Resource
	private FieldAccessService service;
	@Resource
	private HtmlTemplateService tempService;
	@Resource
	private FormService formService;
	@Resource
	private WorkflowNodeService nodeService;

	@Resource
	WorkflowUtil workflowUtil;

	@RequestMapping("/start")
	public void start(@ModelAttribute Collection<WorkflowNode> workflowNames,@ModelAttribute Collection<HtmlFormTemplate> htmlTemplates) {

		workflowNames = nodeService.findAll();
		htmlTemplates = tempService.findAll();

	}

	@RequestMapping("/init")
	public void init(
			
			@ModelAttribute SortedMap<Integer, String> stepIdNames,
			@ModelAttribute HtmlFormTemplate htmlTemplate,
			@ModelAttribute String formField
			) throws Exception {
		stepIdNames = workflowUtil
				.getStepInfomation(Workflow.WORKFLOW_DESCRIPTOR.get());
		htmlTemplate = tempService.find(htmlTemplate.getId());
        
		
		formField = formService.extractHtmlElementsToJson(htmlTemplate );
	}

	@RequestMapping("/readonly")
	public void readonly(@ModelAttribute Collection<FieldAccess> beans,String refname,long step) throws Exception {
		beans = service.getReadonly(refname,step);
	
	}	

}